package impl

import (
	"adam2/internal/vo"
	pConstants "anubis-framework/pkg/constants"
	pDomain "anubis-framework/pkg/domain"
	"anubis-framework/pkg/util"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

type StockTransactionDataAllControllerImpl struct {
	*BaseControllerImpl
}

// StockTransactionDataAllControllerImpl
func GetStockTransactionDataAllControllerImpl() *StockTransactionDataAllControllerImpl {
	return &StockTransactionDataAllControllerImpl{GetBaseControllerImpl()}
}

// 根据code、开始时间和结束时间查询数据，并按照日期升序排列
func (_stockTransactionDataAllControllerImpl StockTransactionDataAllControllerImpl) FindByCodeBetweenDateOrderByDateAsc(c *gin.Context) {
	// 转换参数
	var findStockTransactionDataAllVo *vo.FindStockTransactionDataAllVo = &vo.FindStockTransactionDataAllVo{}
	c.BindJSON(findStockTransactionDataAllVo)

	// 参数验证：参数code不能为空
	if findStockTransactionDataAllVo.Code == "" {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数code不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	// 参数验证：参数BeginDate和EndDate不能为空
	if findStockTransactionDataAllVo.BeginDate == "" || findStockTransactionDataAllVo.EndDate == "" {
		var apiResult *pDomain.ApiResult = &pDomain.ApiResult{}
		apiResult.Code = pConstants.OPERATION_FAIL_CODE
		apiResult.Message = "参数BeginDate和EndDate不能为空"
		apiResult.Success = false

		c.JSON(http.StatusBadRequest, *apiResult)
		return
	}

	// 返回收益率折线图数据
	var _beginDate time.Time = util.StringToDate(findStockTransactionDataAllVo.BeginDate)
	var _endDate time.Time = util.StringToDate(findStockTransactionDataAllVo.EndDate)
	var serviceResult *pDomain.ServiceResult = _stockTransactionDataAllControllerImpl._stockTransactionDataAllServiceImpl.FindByCodeBetweenDateOrderByDateAsc(findStockTransactionDataAllVo.Code, _beginDate, _endDate)
	var code, apiResult = util.ServiceResultToApiResult(serviceResult)
	c.JSON(code, *apiResult)
	return
}
